package com.zhixiang.xaec.action.system;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.util.String2Array;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.system.Staff;
import com.zhixiang.xaec.service.system.StaffService;

@Controller
@Scope("prototype")
public class StaffAction extends BaseAction
{

    private static final long serialVersionUID = 8709402663321992599L;

    private Staff staff;
    
    @Autowired
    private StaffService staffService;
    

    public String list(){
        QueryFilter localQueryFilter = new QueryFilter(getRequest());
        List<Staff> list = staffService.getAll(localQueryFilter);
        setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
        setResult(list);
        return SUCCESS;
    }
    
    public String get(){
        if(staff!=null&&StringUtils.isNotEmpty(staff.getId().toString())){
            setResult(staffService.get(staff.getId()));
        }
        return SUCCESS;
    }
    
    public String delete(){
        String ids = getRequest().getParameter("ids");
        Long[] l = String2Array.stringToLongArray(ids);
        staffService.remove(l);
        return SUCCESS;
    }
    
    public String save(){
        staffService.save(staff);
        return SUCCESS;
    }
    
    
    public Staff getStaff()
    {
        return staff;
    }

    public void setStaff(Staff staff)
    {
        this.staff = staff;
    }
    
}
